{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 Teclib' and contributors.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% extends "pages/setup/general/base_form.html.twig" %}
{% import 'components/form/fields_macros.html.twig' as fields %}

{% set field_options = {
   'full_width': true,
   'rand': rand|default(random())
} %}

{% block config_fields %}
   {{ fields.largeTitle(__('Password security policy'), 'ti ti-shield-lock') }}

   {{ fields.smallTitle(__('Security policy validation')) }}
   {{ fields.sliderField(
      'use_password_security',
      config['use_password_security'],
      __('Force passwords to comply with security policy'),
      field_options
   ) }}

   {% if config['use_password_security'] %}
      {{ fields.smallTitle(__('Security policy configuration')) }}

      {{ fields.numberField(
         'password_min_length',
         config['password_min_length'],
         __('Password minimum length'),
          field_options|merge({'min': 4})
      ) }}

      {{ fields.sliderField(
         'password_need_number',
         config['password_need_number'],
         __('Password need digit'),
          field_options
      ) }}

      {{ fields.sliderField(
         'password_need_letter',
         config['password_need_letter'],
         __('Password need lowercase character'),
          field_options
      ) }}

      {{ fields.sliderField(
         'password_need_caps',
         config['password_need_caps'],
         __('Password need uppercase character'),
          field_options
      ) }}

      {{ fields.sliderField(
         'password_need_symbol',
         config['password_need_symbol'],
         __('Password need symbol'),
          field_options
      ) }}
   {% endif %}

   {{ fields.largeTitle(__('Password expiration policy'), 'ti ti-calendar-time') }}

   {{ fields.dropdownNumberField(
      'password_expiration_delay',
      config['password_expiration_delay'],
      __('Password expiration delay (in days)'),
       field_options|merge({
         'min': 15,
         'max': 365,
         'step': 5,
         'toadd': {'-1': __('Never')},
         'width': 'auto'
      })
   ) }}

   {{ fields.dropdownNumberField(
      'password_expiration_notice',
      config['password_expiration_notice'],
      __('Password expiration notice time (in days)'),
       field_options|merge({
         'min': 0,
         'max': 30,
         'step': 1,
         'toadd': {'-1': __('Notification disabled')},
         'width': 'auto'
      })
   ) }}

   {{ fields.dropdownNumberField(
      'password_expiration_lock_delay',
      config['password_expiration_lock_delay'],
      __('Delay before account deactivation (in days)'),
       field_options|merge({
         'min': 0,
         'max': 30,
         'step': 1,
         'toadd': {'-1': __('Do not deactivate')},
         'width': 'auto'
      })
   ) }}

   {{ fields.dropdownTimestampField(
      'password_init_token_delay',
      config['password_init_token_delay'],
      __('Validity period of the password initialization token'),
       field_options|merge({
         'min': constant('DAY_TIMESTAMP'),
         'max': constant('MONTH_TIMESTAMP'),
         'step': constant('DAY_TIMESTAMP'),
         'width': 'auto'
      })
   ) }}

   {{ fields.dropdownArrayField(
      'non_reusable_passwords_count',
      config['non_reusable_passwords_count'],
      {
         '1': __('Last password'),
         '2': __('Last %s passwords')|format(2),
         '3': __('Last %s passwords')|format(3),
         '4': __('Last %s passwords')|format(4),
         '5': __('Last %s passwords')|format(5)
      },
      __('Prevent users from reusing previous passwords'),
       field_options|merge({
         'width': 'auto'
      })
   ) }}

   {{ fields.largeTitle(__('Two-factor authentication (2FA)'), 'ti ti-2fa') }}

   {{ fields.sliderField(
      '2fa_enforced',
      config['2fa_enforced'],
      __('Enforce 2FA'),
       field_options
   ) }}

   {% if config['2fa_enforced'] %}
      {{ fields.numberField(
         '2fa_grace_days',
         config['2fa_grace_days'],
         __('2FA grace period (in days)'),
          field_options|merge({
            'min': 0,
            'max': 365,
         })
      ) }}
   {% endif %}

{% endblock %}
